<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta name="author" content="">
    <title></title>
    <% include("../inc/list_css.html"){}%>
</head>
<body>
<div class="ibox ">
    <div class="ibox-title">
        <div class="pull-left mbx navbar_title">
            <span>品牌账号 </span>
            <span class="line">/</span>
            角色管理
        </div>
    </div>

    <div class="ibox-content">
        <div class="wrapper wrapper-content">
            <div class="row">
                <div class="col-md-12">

                    <div class="btn-group margin-vertical-4_0">
                        <button class="hive-btn-md-large hive-btn-primary" id="add">
                            <i class="icon-add" aria-hidden="true"></i>&nbsp;添加角色
                        </button>
                    </div>
                    <table data-toggle="table " id="table" data-show-export="true" class=" table-striped table-no-bordered fixed-table-container table-row-border-color table-hovered table-hover">
                        <thead class="table-header">
                        <tr>
                            <th data-field="name">角色名称</th>
                            <th data-field="modifyDate">修改日期</th>
                            <th data-field="head" data-formatter="opFormatter" data-halign="center"  data-align="center" data-width="120">操作</th>
                        </tr>
                        </thead>
                    </table>

                </div>
            </div>
        </div>
    </div>
</div>


<% include("../inc/list_js.html"){}%>
<script>

    function opFormatter(value, row, index){
        var html = '<a href="javascript:void(0)" class="icon-edit hive_icon color_normal" onclick="edit(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="编辑"></a>';
        html += '<a href="javascript:void(0)" class="icon-spread hive_icon color_normal" onclick="openWindow(\''+row.id+'\',\''+row.name+'\');" data-toggle="tooltip" data-placement="top" title="资源列表"></a>';
        html += '<a href="javascript:void(0)" class="icon-delete hive_icon color_danger" onclick="del(\''+row.id+'\');" data-toggle="tooltip" data-placement="top" title="删除"></a>';
        return html;
    }

    function nameFormatter(value, row, index) {
        if(row.valuenames){
            return value + "<span style='color: #00a0e9;margin-left: 5px'>["+row.valuenames+"]</span>";
        }else
            return value;
    }

    function boolFormatter(v) {
        if(v)
            return '是';
        else
            return '否';
    }

    function typeFormatter(v) {
        if(v == 0)
            return '文本';
        else if(v == 1)
            return '数字';
        else if(v == 2)
            return '字母';
        else if(v == 3)
            return '单选项';
        else if(v == 4)
            return '多选项';
        else if(v == 5)
            return '日期';
    }

    function del(v) {
        parent.layer.confirm('您确定要删除吗?', {
            shade: [0.3,'#fff'],//0.1透明度的白色背景
            btn: ['是','否'] //按钮
        }, function(){
            $.post('delete',{"ids":v},function (e) {
                if(e.state == "fail"){
                    parent.layer.msg(e.info);
                }else{
                    parent.layer.msg("删除成功!");
                    $('#table').bootstrapTable('refresh');
                }
            });
        });
    }


    function edit(v) {
        location.href = "edit?id="+v;
    }
    function openWindow(id,name) {
        parent.layer.open({
            type: 2,
            title: name+'的角色资源配置',
            //shadeClose: true,
            //shade: 0.8,
            shade: [0.3,'#fff'],//0.1透明度的白色背景
            area: ['380px', '60%'],
            content: '${base}/shop/role/resource?roleId='+id //iframe的url
        });
    }

    (function () {

        $('#table').bootstrapTable({
            url: "ajaxlist",
            dataType: 'json',
            contentType: 'application/json',
            search: true,
            searchAlign: 'right',
            pagination: true,
            showRefresh: true,
            pageSize: 20,
            showToggle: false,//是否显示card/table切换按钮
            showColumns: true,//是否显示内容列下拉框
            pageList: [20, 50, 100],
            iconSize: 'outline',
            toolbar: '#eventsToolbar',
            paginationHAlign: 'right', //right, left
            paginationVAlign: 'bottom',
            icons: {
                refresh: 'icon-refresh',
                toggle: 'glyphicon-list-alt',
                columns: 'icon-select',
                export: 'icon-export'
            },
            responseHandler: function (res) {
                $("#dsh").html(res.length);
                return res;
            },
            formatNoMatches: function () { //判断有无数据
                var imghtml = '<div class="flexed_column content_center content_alignCenter padding-20"><img src="https://static.9hive.cn/global/img/nodata.png" class="no_data"/><span class="font-size-16">暂无数据</span></div>';
                return imghtml;
            },
            formatLoadingMessage: function () {  //数据加载中样式
                return ' <div id="loading"><div id="loading-center">' +
                    '<div id="loading-center-absolute"><div class="object" id="object_one">' +
                    '</div><div class="object" id="object_two"></div><div class="object" id="object_three">' +
                    '</div><div class="object" id="object_four"></div></div></div>努力加载中...</div>'
            },
        });

        $('#add').on('click', function (e) {
            location.href = 'add';
        });

        $(".wrapper").tooltip({selector: "[data-toggle=tooltip]", container: "body"});

    })();

</script>
</body>
</html>